package com.fzhucc.modules.lesson.repository;

import com.fzhucc.modules.lesson.domain.LessonSecondChapter;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
* @website https://eladmin.vip
* @author yyg
* @date 2022-12-08
**/
public interface LessonSecondChapterRepository extends JpaRepository<LessonSecondChapter, Integer>, JpaSpecificationExecutor<LessonSecondChapter> {

    @Query("SELECT a from LessonSecondChapter as a where a.firstChapterId=:firstChapterId")
    List<LessonSecondChapter> findByFirstChapterId(int firstChapterId);

    /**
     * 根据一级分类id删除所有二级菜单
     * @param firstChapterId 一级分类id
     */
    @Modifying
    @Query(value = "delete from tb_lesson_second_chapter where first_chapter_id = ?1",nativeQuery = true)
    void deleteByFirstChapterId(int firstChapterId);
}